﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace VoiceTestPlatform
{
    public class ParameterViewModel : ViewModelBase
    {
        public ParameterViewModel()
        {
            SelectRecordPathCommand = new DelegateCommand(SelectRecordPathCommandAction);
            SelectArtificalPathCommand = new DelegateCommand(SelectArtificalPathCommandAction);
            playDelay = ParameterManager.PlayDelay.ToString();
            voiceDelay = ParameterManager.VoiceDelay.ToString();
        }

        private void SelectRecordPathCommandAction(object obj) {

            System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();

            folderBrowserDialog.SelectedPath = ParameterManager.RecordPath;
            
            System.Windows.Forms.DialogResult result = folderBrowserDialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                ParameterManager.RecordPath = folderBrowserDialog.SelectedPath;
                RaisePropertyChanged("RecordPath");
                
               
            }
        }
        private void SelectArtificalPathCommandAction(object obj) {

            System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();

            folderBrowserDialog.SelectedPath = ParameterManager.ArtificialPath;

            System.Windows.Forms.DialogResult result = folderBrowserDialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                ParameterManager.ArtificialPath = folderBrowserDialog.SelectedPath;
                RaisePropertyChanged("ArtificalPath");


            }
        }

        public DelegateCommand SelectRecordPathCommand { get; set; }
        public DelegateCommand SelectArtificalPathCommand { get; set; }

       

        public string RecordPath
        {
            get { return ParameterManager.RecordPath; }
            //set { recordPath = value; RaisePropertyChanged("RecordPath"); }
        }

        public string ArtificalPath
        {
            get { return ParameterManager.ArtificialPath; }
            //set { recordPath = value; RaisePropertyChanged("RecordPath"); }
        }

        private string playDelay;
        public string PlayDelay
        {
            get { return playDelay; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    int i = 0;
                    if (int.TryParse(value, out i))
                    {
                        ParameterManager.PlayDelay = i;
                    }
                    else
                    {
                        App.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                        {
                            RaisePropertyChanged("PlayDelay");
                        }));
                        return;
                    }
                }
                playDelay = value;
                RaisePropertyChanged("PlayDelay");
            }
        }

        private string voiceDelay;
        public string VoiceDelay
        {
            get { return voiceDelay; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    int i = 0;
                    if (int.TryParse(value, out i))
                    {
                        ParameterManager.VoiceDelay = i;
                    }
                    else
                    {
                        App.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                        {
                            RaisePropertyChanged("VoiceDelay");
                        }));
                        return;
                    }
                }
                voiceDelay = value;
                RaisePropertyChanged("VoiceDelay");
            }
        }

    }
}
